package com.example.lanouhn.firstapp.activity.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;

import com.example.lanouhn.firstapp.R;
import com.example.lanouhn.firstapp.activity.model.Carousel;

import java.util.List;

/**
 * 首页搜索跳转商品列表界面数据适配器
 * <p/>
 *
 */
public class CarouselAdapter extends BaseAdapter {

    private Context context;
    private List<Carousel> iList;


    public CarouselAdapter(Context context, List<Carousel> iList) {
        this.context = context;
        this.iList = iList;
    }

    @Override
    public int getCount() {
        return iList.size();
    }

    @Override
    public Object getItem(int i) {
        return iList.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        ViewHolder holder = null;
        if (view == null) {
            //判断缓存中是否有内容  没有则创建 有的话 使用缓存中的内容
            holder = new ViewHolder();
            //绑定布局文件
            view = LayoutInflater.from(context).inflate(R.layout.image_layout, null);
            //绑定控件id
            holder.image = (ImageView) view.findViewById(R.id.image);

            view.setTag(holder);
        }else {
            //使用缓存中的内容
            holder = (ViewHolder) view.getTag();

        }

        Carousel carousel = iList.get(i);
        //使用Picasso 加载图片
        //Picasso.with(context).load(Carousel.get)
        return view;
    }


    class ViewHolder {

        private ImageView image;


    }
}
